/**
 * @function 前序遍历递归法，递归顺序:左->右->中
*/

const postorderTraversal = (root) => {
  let res = []
  const postorder = root => {
    if (!root) return res
    postorder(root.left)
    postorder(root.right)
    res.push(root.val)
  }
  postorder(root)
  return res
}

const root = {
  val: 1,
  left: {
      val: 2,
      left: null,
      right: null
  },
  right: {
      val: 3,
      left: null,
      right: null
  }
}

console.log(postorderTraversal(root));